import 'package:center_beijing/common/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class TextAreaWidget extends StatefulWidget {
  final String labelText;
  final String fieldName;
  final String defaultValue;
  final String placeholder;
  final bool disabled;
  final bool required;
  final int rows;
  final Function onChange;
  final TextEditingController textController;
  final bool readOnly;
  final double titleFont;
  final int maxLength;
  final Color titleColor;
  TextAreaWidget(
      {this.labelText,
        this.readOnly = false,
        this.textController,
        this.maxLength=100,
        this.titleFont,
        this.titleColor = Styles.DetailColor,
        this.fieldName,
        this.defaultValue,
        this.placeholder,
        this.disabled,
        this.required,
        this.rows,
        this.onChange});


  @override
  _TextAreaWidgetState createState() => _TextAreaWidgetState();
}

class _TextAreaWidgetState extends State<TextAreaWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      // color: Theme.of(context).cardColor,
      padding: EdgeInsets.fromLTRB(8, 8, 8, 0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Container(
            child: Padding(
              padding: EdgeInsets.only(right: 8),
              child: Row(
                children: <Widget>[
                  widget.required
                      ? Text(
                    "*",
                    style: TextStyle(
                        fontSize: widget.titleFont!=null?widget.titleFont:Styles.MiddleFont17,
                        color: Color.fromRGBO(242, 114, 94, 1)),
                  )
                      : Container(),
                  Text(widget.labelText, style: TextStyle(fontSize: widget.titleFont!=null?widget.titleFont:widget.titleFont!=null?widget.titleFont:Styles.MiddleFont17,color: widget.titleColor)),
                ],
              ),
            ),
          ),
          TextField(
            controller: widget.textController,
            maxLength: widget.maxLength,
            maxLines: widget.rows,
            textAlign: TextAlign.left,
            readOnly: widget.readOnly,
            style: TextStyle(fontSize: widget.titleFont!=null?widget.titleFont:Styles.MiddleFont17),
            decoration: InputDecoration(
              hintStyle: TextStyle(fontSize: widget.titleFont!=null?widget.titleFont:Styles.MiddleFont17,color:  Styles.LeftTitleColor),
              hintText: widget.placeholder == ""
                  ? "请输入" + widget.labelText
                  : widget.placeholder,
              border: InputBorder.none,
            ),
            enabled: !widget.disabled,
            onChanged: (value) {
              if(widget.onChange!=null){
                widget.onChange(value);
              }
            },
          ),
        ],
      ),
    );
  }
}
